package com.zxmr.webclient.servlet;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class DispatchExecutors {

	Executor executor = null;
	static int defaultMinThread = 10;
	static int defaultMaxThread = 30;
	static int defaultFreeTime = 30;
	static int defaultQueueSize = 100;
	
	public DispatchExecutors(int minThread,int maxThread,int threadFreeTime,int threadBlockQueueSize)
	{
		executor = new ThreadPoolExecutor(minThread,maxThread,threadFreeTime,TimeUnit.SECONDS,
				new ArrayBlockingQueue<Runnable>(threadBlockQueueSize),
				new ThreadPoolExecutor.CallerRunsPolicy());
	}
	public DispatchExecutors(int minThread,int maxThread)
	{
		this(minThread,maxThread,defaultFreeTime,defaultQueueSize);
	}
	public DispatchExecutors()
	{
		this(defaultMinThread,defaultMaxThread,defaultFreeTime,defaultQueueSize);
	}
	
	public void execut(Runnable run)
	{
		executor.execute(run);
	}
}
